import CryptoJS from 'crypto-js'

const BASE = {
	// 开发版
	develop: {
		key: 'pigxpigxpigxpigx',
		iv: 'pigxpigxpigxpigx'
	},
	// 体验版
	trial: {
		key: 'pigxpigxpigxpigx',
		iv: 'pigxpigxpigxpigx'
	},
	// 正式版
	release: {
		key: 'pigxpigxpigxpigx',
		iv: 'pigxpigxpigxpigx'
	}
};
BASE.development = BASE.develop;
BASE.production = BASE.release;

// #ifdef MP-WEIXIN
const accountInfo = wx.getAccountInfoSync();
const env = accountInfo.miniProgram.envVersion;
const AES = BASE[env];
// #endif
// #ifdef H5
const env = process.env.NODE_ENV
const AES = BASE[env];
// #endif

export default { //加密
	encrypt(data, keyStr) {
		const key = CryptoJS.enc.Utf8.parse(AES.key);
		const ivs = CryptoJS.enc.Utf8.parse(AES.iv);
		const encrypted = CryptoJS.AES.encrypt(data, key, {
			iv: ivs,
			mode: CryptoJS.mode.CBC,
			padding: CryptoJS.pad.ZeroPadding
		});
		return encrypted.toString();
	},
}
